﻿using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Text;

namespace DAL
{
    public class MyDBContext : DbContext
    {
        public DbSet<UserInfo> UserInfo { get; set; }
        public DbSet<RoomType> RoomType { get; set; }
        public DbSet<RoomIntensive> RoomIntensive { get; set; }
        public DbSet<RoleInfo> RoleInfo { get; set; }
        public DbSet<RoleMenu> RoleMenu { get; set; }
        public DbSet<Professional> Professional { get; set; }
        public DbSet<Payment> Payments { get; set; }
        public DbSet<PatientInfor> PatientInfor { get; set; }
        public DbSet<Patient> Patient { get; set; }
        public DbSet<Outpatient> Outpatient { get; set; }
        public DbSet<Outcalls> Outcall { get; set; }
        public DbSet<MenuInfo> MenuInfo { get; set; }
        public DbSet<Doctor> Doctor { get; set; }
        public DbSet<Discount> Discount { get; set; }
        public DbSet<ChargeType> ChargeType { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Data Source=10.3.157.16;Initial Catalog=MedicalSystem;User ID=sa;pwd=123456");
        }

        //指定主键
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<UserInfo>().HasKey(e => e.User_Id);
            modelBuilder.Entity<RoomType>().HasKey(e => e.RoomType_Id);
            modelBuilder.Entity<RoomIntensive>().HasKey(e => e.RoomIntensive_Id);
            modelBuilder.Entity<RoleMenu>().HasKey(e => e.RoleMenu_Id);
            modelBuilder.Entity<RoleInfo>().HasKey(e => e.Role_Id);
            modelBuilder.Entity<Professional>().HasKey(e => e.Professional_Id);
            modelBuilder.Entity<Payment>().HasKey(e => e.Payment_Id);
            modelBuilder.Entity<PatientInfor>().HasKey(e => e.PatientInfor_Id);
            modelBuilder.Entity<Patient>().HasKey(e => e.Patient_Id);
            modelBuilder.Entity<Outpatient>().HasKey(e => e.Outpatient_Id);
            modelBuilder.Entity<Outcalls>().HasKey(e => e.Outcalls_Id);
            modelBuilder.Entity<MenuInfo>().HasKey(e => e.Menu_Id);
            modelBuilder.Entity<Doctor>().HasKey(e => e.Doctor_Id);
            modelBuilder.Entity<Discount>().HasKey(e => e.Discount_Id);
            modelBuilder.Entity<ChargeType>().HasKey(e => e.ChargeType_Id);
            modelBuilder.Entity<Discount>().Property(e => e.Discount_Rate).HasColumnType("decimal(18,2)");
            modelBuilder.Entity<Payment>().Property(e => e.Payment_Actual).HasColumnType("decimal(18,2)");
            modelBuilder.Entity<Payment>().Property(e => e.Payment_Sum).HasColumnType("decimal(18,2)");
            modelBuilder.Entity<PatientInfor>().Property(e => e.PatientInfor_registration).HasColumnType("decimal(18,2)");
        }
    }
}
